package edu.cuit.jead.mynetdisk.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.cuit.jead.mynetdisk.entity.User;
import org.apache.ibatis.annotations.*;
import edu.cuit.jead.mynetdisk.entity.Fileinfo;

import java.sql.Date;
import java.util.List;

@Mapper
public interface FileMapper extends BaseMapper<Fileinfo> {
    @Select("SELECT * FROM user WHERE email=#{email}")
    User getUserByEmail(String email);
    @Select("SELECT CURRENT_TIME")
    Date getCurrentTime();
    @Insert("INSERT INTO fileinfo (email, collected, recycled, shared, uploadtime, lastedit, userID, path, size) VALUES (#{email}, #{collected}, #{recycled}, #{shared}, #{uploadtime}, #{lastedit}, #{userID}, #{path}, #{size})")
    int insertfile(Fileinfo file);
    @Select("SELECT * FROM fileinfo WHERE email=#{email}")
    List<Fileinfo> getFileByEmail(String email);
    @Delete("DELETE FROM fileinfo WHERE path=#{path}")
    int deleteFile(String path);
    @Select("SELECT  recycled FROM fileinfo where path=#{path}")
    Integer getRecycled(String path);
    @Select("SELECT  size FROM fileinfo where path=#{path}")
    Long getSize(String path);
    @Select("SELECT  usedspace FROM user where email=#{email}")
    Long getUsedSpace(String email);
    @Select("SELECT  totalspace FROM user where email=#{email}")
    Long getTotalSpace(String email);
    @Update("UPDATE fileinfo SET recycled = #{recycled} WHERE path = #{path}")
    int updateRecycled(@Param("path") String path, @Param("recycled") Integer recycled);
    @Update("UPDATE user SET usedspace = #{usedspace} WHERE email = #{email}")
    int updateUsedSpace(@Param("email") String email, @Param("usedspace") Long usedspace);
    @Select("SELECT  collected FROM fileinfo where path=#{path}")
    Integer getCollected(String path);
    @Update("UPDATE fileinfo SET collected = #{collected} WHERE path = #{path}")
    int updateCollect(@Param("path") String path, @Param("collected") Integer collected);

}
